import { Group } from "../Data/GameData";
import GameManager from "../Managers/GameManager";

const {ccclass, property} = cc._decorator;

@ccclass
export default class Hole extends cc.Component {

    catchWood:cc.Node[] = [];

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

    start () {

    }

    // update (dt) {}

    CheckWood(){
        GameManager.Instance.woodArr.forEach(item => {
            if(item.getBoundingBox().contains(cc.v2(this.node.position))) this.catchWood.push(item);
        });
    }

    onBeginContact(contact:cc.PhysicsContact, selfCollider:cc.PhysicsCollider, otherCollider:cc.PhysicsCollider){
        if(otherCollider.node.group == Group.HWood || otherCollider.node.group == Group.VWood){
            if(this.catchWood.indexOf(otherCollider.node) == -1) this.catchWood.push(otherCollider.node);
        } 
    }

    onEndContact(contact:cc.PhysicsContact, selfCollider:cc.PhysicsCollider, otherCollider:cc.PhysicsCollider) {
        if(otherCollider.node.group == Group.HWood || otherCollider.node.group == Group.VWood){
            if(this.catchWood.indexOf(otherCollider.node) != -1) this.catchWood.splice(this.catchWood.indexOf(otherCollider.node), 1);
        } 
    }
}
